<?php
class PhotoUtility
{
    public static function add($userId, $filename)
    {
        $photo = new PhotoModel();
        $photo->user_id = $userId;
        $photo->filename = $filename;
        $photo->save();
        
        return $photo;
    }
    
    public static function addByUrl($userId, $url)
    {
        // photo
        $filename = FileUtility::download($url, self::getPath());
        $photo = self::add($userId, $filename);
        
        // thumbnail
        ThumbnailUtility::addByPhoto($photo);

        return $photo->id;
    }
    
    public static function getPath()
    {
        return Yii::app()->params[ENUM_CONFIG_PARAM_PHOTO_PATH].'/'. Yii::app()->params[ENUM_CONFIG_PARAM_PHOTO_ORIGIN_FOLDER];
    }

    public static function getUrl()
    {
        return Yii::app()->params[ENUM_CONFIG_PARAM_PHOTO_URL].'/'.Yii::app()->params[ENUM_CONFIG_PARAM_PHOTO_ORIGIN_FOLDER];
    }
}